
//Simple Client

import java.io.*;
import java.net.*;

public class SimpleClient02 {

    public static void main(String arg[]){
	Writer		writer = null;
	BufferedReader	reader = null;
	String		msg    = null;
	Socket		sk = null;
	int		msgCount = 0;

	try {
	    sk = new Socket("sleipnir.cs.csubak.edu", 9902);
	    writer = new BufferedWriter (
		    	new OutputStreamWriter (sk.getOutputStream() )) ;
	    reader = new BufferedReader (
		    	new InputStreamReader (sk.getInputStream () )) ;

	    while ( true ) {

		msg = "message from from client " + ++ msgCount ;
	        writer.write( msg, 0, msg.length() );
	    	writer.flush();

		System.out.printf("SimpleServer02 Doesn't readLine() this string: %s\n", msg);

		msg = reader.readLine();
	 	System.out.printf("client: %s\n", msg );

	    	Thread.sleep(1000);
	    }

	}
	catch(Exception e) { e.printStackTrace(); } 

    }

}
